<!-- 个人·商品管理 -->
<template>
	<section>
		<!-- 搜索 -->
		<el-col :span="24" class="toolbar" style="display: flex;justify-content: space-between;height: 60px;">
			<div>
				<p class="text">个人商品管理</p>
			</div>
			<el-form :inline="true">
				<el-form-item>
					    <el-button type="primary" size="small" class="search-btn" icon="el-icon-search"  @click="handlsearch()">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>
		<!--列表-->
		<el-table :data="List" v-loading="loading" @selection-change="selsChange" border :cell-style="cellStyle" :header-cell-style="rowClass" style="width: 100%;">
			<el-table-column prop="id" align="center" label="ID" width="90"></el-table-column>
			<el-table-column prop="realName" align="center" label="用户名"></el-table-column>
			<el-table-column prop="phone" align="center" label="手机号"></el-table-column>
			<el-table-column prop="teamNum" align="center" label="团队实名人数"></el-table-column>
			<el-table-column prop="temmTotal" align="center" label="团队总人数" ></el-table-column>
			<el-table-column prop="funsActivation" align="center" label="团队获取度" ></el-table-column>
			<el-table-column prop="activation" align="center" label="个人活跃度" ></el-table-column>
			<el-table-column prop="goodsCount" align="center" label="商品数量"></el-table-column>
			<el-table-column prop="goodsSaleCount" align="center" label="商品销量"></el-table-column>
			<el-table-column label="操作" align="center" >
				<template slot-scope="scope">
					<el-button size="small" type="primary" icon="el-icon-view" @click="handleLook(scope.$index, scope.row)">查看</el-button>
				</template>
			</el-table-column>
		</el-table>
		<!--批量删除-->
		<el-col :span="24" class="toolbar">
			<el-pagination background layout="total,sizes,prev, pager, next,jumper" @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-size="10" :total="total" style="float:right;">
			</el-pagination>
		</el-col>
		<!-- 查看用户商品列表-->
		<el-dialog title="商品列表查看" :visible.sync="dialogVisible" width="73%" :before-close="handleClose">
			<div style="margin-top: -20px; padding-bottom: 11px;text-align: right;">
				<el-button type="primary" size="mini" class="search-btn" icon="el-icon-search"  @click="handlList()">查询</el-button>
			</div>
			<el-table :data="LookList" highlight-current-row v-loading="seeloading" @selection-change="selsChange" border :cell-style="cellStyle" :header-cell-style="rowClass" style="width: 100%;">
				<el-table-column type="expand">
				  <template slot-scope="props">
				    <el-form label-position="left" inline class="demo-table-expand">
						<el-form-item label="商品编号:">
							<span>{{ props.row.goodsNumber }}</span>
						</el-form-item>
						<el-form-item label="商品邮费:">
							<span>{{ props.row.expressPrice }}</span>
						</el-form-item>
						<el-form-item label="商品投诉量:">
							<span>{{ props.row.problemCount }}</span>
						</el-form-item>
				    </el-form>
				  </template>
				</el-table-column>
				<el-table-column prop="id" align="center" label="ID" width="80"></el-table-column>
				<el-table-column prop="categoryName" align="center" label="商品分类" width="100"></el-table-column>
				<el-table-column prop="goodsName" align="center" label="商品名称" width="260"></el-table-column>
				<el-table-column prop="goodsType" align="center" label="商品类型" :formatter="formatType"></el-table-column>
				<el-table-column prop="goodsState" align="center" label="商品状态" :formatter="formatState"></el-table-column>
				<el-table-column prop="saleCount" align="center" label="商品销量"></el-table-column>
				<el-table-column prop="createTime" align="center" label="创建时间" width="170"></el-table-column>
				<el-table-column label="操作" align="center" width="200">
					<template slot-scope="scope">
						<el-button size="small" type="success" icon="el-icon-view" @click="handleSee(scope.$index, scope.row)">查看</el-button>
						<el-button size="small" type="primary" icon="el-icon-edit" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
					</template>
				</el-table-column>
			</el-table>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible = false">取 消</el-button>
			</span>
		</el-dialog>
		<!-- 修改用户商品状态-->
		<el-dialog title="商品状态修改" :visible.sync="dialogEdit" width="73%" :before-close="handleClose">
			<el-form :model="editForm" label-width="80px" :rules="editFormRules" ref="editForm">
				<el-form-item label="修改原因" prop="reason">
					<el-input v-model="editForm.reason" auto-complete="off" placeholder="请输入操作订单的原因"></el-input>
				</el-form-item>
				<el-form-item label="修改状态" prop="goodsState">
					<el-radio-group v-model="editForm.goodsState">
						<el-radio class="radio" :label="1">上架</el-radio>
						<el-radio class="radio" :label="0">下架</el-radio>
					</el-radio-group>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogEdit = false">取 消</el-button>
				<el-button type="primary"  @click.native="editSubmit" >确定</el-button>
			</span>
		</el-dialog>
		<!-- 查看商品详情-->
		<el-dialog title="商品详情查看" :visible.sync="dialogDetail" width="60%" :before-close="handleClose">
			<el-table :data="Detail" highlight-current-row v-loading="loading" @selection-change="selsChange" border :cell-style="cellStyle" :header-cell-style="rowClass" style="width: 100%;">
				<el-table-column type="expand">
				  <template slot-scope="props">
				    <el-form label-position="left" inline class="demo-table-expand">
						<el-form-item label="商品编号:">
							<span>{{ props.row.goodsNumber }}</span>
						</el-form-item>
						<el-form-item label="商品展示">
							<img :src="props.row.bigChart" alt="" width="30%">
						</el-form-item>
						<el-form-item label="商品介绍:">
							<span>{{ props.row.detailContent }}</span>
						</el-form-item>
						<el-form-item label="商品邮费:">
							<span>{{ props.row.expressPrice }}</span>
						</el-form-item>
						<el-form-item label="投诉量:">
							<span>{{ props.row.problemCount }}</span>
						</el-form-item>
						<el-form-item label="商品信息:">
							<el-table :data="Detaillist" style="width: 100%" row-key="id" border>
							    <el-table-column align="center" prop="id" label="规格ID:" width="80"></el-table-column>
							    <el-table-column align="center" prop="specsName" label="商品规格"></el-table-column>
							    <el-table-column align="center" prop="price" label="价格"></el-table-column>
								<el-table-column align="center" prop="stockTotal" label="库存问题"></el-table-column>
								<el-table-column align="center" prop="stock" label="当前库存"></el-table-column>
								<el-table-column align="center" prop="isDefault" label="是否默认" :formatter="formatDefault"></el-table-column>
							</el-table>
						</el-form-item>
				    </el-form>
				  </template>
				</el-table-column>
				<el-table-column prop="id" align="center" label="ID" width="80"></el-table-column>
				<el-table-column prop="categoryName" align="center" label="分类名称"></el-table-column>
				<el-table-column prop="goodsName" align="center" label="商品名称"></el-table-column>
				<el-table-column prop="goodsType" align="center" label="商品类型" :formatter="goodsType"></el-table-column>
				<el-table-column prop="goodsState" align="center" label="商品状态" :formatter="formatState"></el-table-column>
				<el-table-column prop="saleCount" align="center" label="商品销量"></el-table-column>
				<el-table-column prop="createTime" align="center" label="创建时间" width="170"></el-table-column>
			</el-table>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogDetail = false">取 消</el-button>
			</span>
		</el-dialog>
		<!-- 自定义查询 cusexcel-->
		<el-dialog title="自定义查询" :visible.sync="userdialog" width="35%" :before-close="handleClose">
			<el-form :model="userForm" label-width="105px" ref="userForm">
				<el-form-item label="用户ID" prop="id">
					<el-input v-model="userForm.id" auto-complete="off" placeholder="请输入正确的用户ID" style="width: 220px;"></el-input>
				</el-form-item>
				<el-form-item label="手机号码" prop="phone">
					<el-input v-model="userForm.phone" auto-complete="off" placeholder="请输入正确的手机号" style="width: 220px;"></el-input>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="userdialog = false">取 消</el-button>
				<el-button type="primary"  @click.native="userSeach" >查询</el-button>
			</span>
		</el-dialog>
		<!-- 个人商品查询 -->
		<el-dialog title="自定义查询" :visible.sync="goodsdialog" width="35%" :before-close="handleClose">
			<el-form :model="goodsForm" label-width="105px" ref="goodsForm">
				<el-form-item label="商品ID" prop="id">
					<el-input v-model="goodsForm.id" auto-complete="off" placeholder="请输入正确的用户ID" style="width: 220px;"></el-input>
				</el-form-item>
				<el-form-item label="分类ID" prop="categoryId">
					<el-input v-model="goodsForm.categoryId" auto-complete="off" placeholder="请输入正确的手机号" style="width: 220px;"></el-input>
				</el-form-item>
				<el-form-item label="商品编号" prop="goodsNumber">
					<el-input v-model="goodsForm.goodsNumber" auto-complete="off" placeholder="请输入正确的手机号" style="width: 220px;"></el-input>
				</el-form-item>
				<el-form-item label="商品类型" prop="goodsType">
					<el-radio-group v-model="goodsForm.goodsType">
						<el-radio class="radio" :label="1">全新</el-radio>
						<el-radio class="radio" :label="2">二手</el-radio>
					</el-radio-group>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="goodsdialog = false">取 消</el-button>
				<el-button type="primary"  @click.native="goodsSeach" >查询</el-button>
			</span>
		</el-dialog>
	</section>
</template>
<script>
	import {
		getGoodsUser,
		getGoodsUserList,
		getGoodsUserDetail,
		editGoodsStatus,
		Refreshtoken
	} from '../../../api/api';

	export default {
		data() {
			return {
				loading: false,
				seeloading: false,
				List: [],
				type:0,
				total: 0,
				page: 1,
				size:10,
				sels: [],//列表选中列
				timer: null,
				dialogVisible:false,
				LookList:[],
				dialogDetail:false,
				Detail:[],
				Detaillist:[],
				State0:'下架',
				State1:'上架',
				dialogEdit:false,
				editForm:{
					reason:'',
					goodsState:1
				},
				editFormRules:{
					reason: [{
						required: true,
						message: '请输入修改商品的原因',
						trigger: 'blur'
					}]
				},
				userdialog:false,
				userForm:{
					id:'',
					phone:'',
				},
				goodsdialog:false,
				goodsForm:{
					id:'',
					categoryId:'',
					goodsNumber:'',
					goodsType:''
				},
			}
		},
		mounted() {
			this.getUsers()
			this.queryInfo();
			this.timer = setInterval(() => {
			   setTimeout(this.queryInfo, 0)
		    }, 600000)
			
		},
		methods: {
			// 设置定时器
			queryInfo() {
				var Token = sessionStorage.getItem('Token');
				var timestamp=new Date().getTime();
				let para = {token: Token,timestamp: timestamp};
				Refreshtoken(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.loading = false;
					}
				});
			},
			// 类型转换
			formatType: function (row, column) {
				return row.goodsType == 1 ? '全新' : row.goodsType == 2 ? '二手' : '未知';
			},
			goodsType:function (row, column) {
				return row.goodsType == 0 ? '全新' : row.goodsType == 1 ? '二手' : '未知';
			},
			formatState:function(row, column) {
				return row.goodsState == 0 ? '下架' : row.goodsState == 1 ? '上架' : '未知';
			},
			formatDefault:function(row, column) {
				return row.isDefault == 0 ? '否' : row.isDefault == 1 ? '是' : '未知';
			},
			selsChange: function (sels) {this.sels = sels;},
			cellStyle({row, column}){return 'text-align:center;padding:5px;';},
			rowClass({row, column}){return 'text-align:center';},
			handleSizeChange(val) {
				this.size = val;
				this.getUsers();
			},
			handleCurrentChange(currentPage) {
				this.page = currentPage;
				this.getUsers();
			},
			handleClose(done) {
				this.$confirm('确认关闭？')
					.then(_ => {
						done();
					})
					.catch(_ => {});
			},
			// 查看用户商品列表
			handleLook(index,row){
				 this.dialogVisible = true;
				 var Token = sessionStorage.getItem('Token');
				 var timestamp=new Date().getTime();
				 this.userId = row.id
				 var para = {
					token: Token,
					curpage:this.page,
					pagesize:this.size,
					timestamp: timestamp,
					userid:row.id
				 };
				 this.loading = true;
				 getGoodsUserList(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.LookList = res.data.list;
						this.loading = false;
					}
				 });
			},
			// 查看商品详情
			handleSee(index,row){
				this.dialogDetail = true
				var Token = sessionStorage.getItem('Token');
				var timestamp=new Date().getTime();
				let para = {
					token: Token,
					timestamp: timestamp,
					id:row.id
				};
				this.loading = true;
				getGoodsUserDetail(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						var obj = res.data;
						var arr=[];
						arr.push(obj)
						this.Detail = arr;
						this.Detaillist = res.data.specsList
						this.loading = false;
					}
				});
			},
			// 修改用户商品状态
			handleEdit(index,row){
				this.dialogEdit = true
				this.editForm = Object.assign({}, row);
				this.pid = row.id
			},
			editSubmit(){
				this.$refs.editForm.validate((valid) => {
					if (valid) {
						this.$confirm('确认修改订单状态吗？', '提示', {}).then(() => {
							var Token = sessionStorage.getItem('Token');
							var timestamp=new Date().getTime();
							var para = {
								token: Token,
								timestamp: timestamp,
								id:this.pid,
								reason:this.editForm.reason,
								goodsState:this.editForm.goodsState,
							};
							this.loading = true;
							editGoodsStatus(para).then((res) => {
								var res = res.data;
								if (res.code != 0) {
									this.$message({
										message: res.message,
										type: 'error'
									});
								} else {
									this.$message({
										type: 'success',
										message: '商品状态修改成功！！！'
									});
									this.$refs['editForm'].resetFields();
									this.dialogEdit= false;
									this.loading = false;
									this.getUsers();
								}
							});
						});
					}
				})
			},
			//查询用户
			handlsearch(){
				this.userdialog = true;
			},
			userSeach(){
				if (this.userForm.id == '' && this.userForm.phone == '') {
					this.$notify({ title: '警告', message: '请输入查询条件', type: 'warning' });
				}else{
					var Token = sessionStorage.getItem('Token');
					var timestamp=new Date().getTime();
					if (this.userForm.id != '') {
						var para = {token: Token,curpage:this.page,pagesize:this.size,timestamp: timestamp,id:this.userForm.id};
					} else if(this.userForm.phone != ''){
						var para = {token: Token,curpage:this.page,pagesize:this.size,timestamp: timestamp,phone:this.userForm.phone};
					}
					this.loading = true;
					getGoodsUser(para).then((res) => {
						var res = res.data;
						if (res.code != 0) {
							this.$message({
								message: res.message,
								type: 'error'
							});
						} else {
							this.$refs['userForm'].resetFields();
							this.total = res.data.total;
							this.List = res.data.list;
							this.loading = false;
							this.userdialog= false;
						}
					});
				}
			},
			// 查询用户的商品
			handlList(){
				this.goodsdialog = true;
			},
			goodsSeach(){
				if (this.goodsForm.id == '' && this.goodsForm.categoryId == '' && this.goodsForm.goodsNumber == '' && this.goodsForm.goodsType == '') {
					this.$notify({ title: '警告', message: '请输入查询条件', type: 'warning' });
				}else{
					var Token = sessionStorage.getItem('Token');
					var timestamp=new Date().getTime();
					if (this.goodsForm.id != '') {
						var para = {token: Token, userid:this.userId,curpage:this.page,pagesize:this.size,timestamp: timestamp,id:this.goodsForm.id};
					}else if(this.goodsForm.categoryId != ''){
						var para = {token: Token,userid:this.userId,curpage:this.page,pagesize:this.size,timestamp: timestamp,categoryId:this.goodsForm.categoryId};
					}else if(this.goodsForm.goodsNumber != ''){
						var para = {token: Token,userid:this.userId,curpage:this.page,pagesize:this.size,timestamp: timestamp,goodsNumber:this.goodsForm.goodsNumber};
					}else if(this.goodsForm.goodsType != ''){
						var para = {token: Token,userid:this.userId,curpage:this.page,pagesize:this.size,timestamp: timestamp,goodsType:this.goodsForm.goodsType};
					}
					this.loading = true;
					getGoodsUserList(para).then((res) => {
						var res = res.data;
						if (res.code != 0) {
							this.$message({
								message: res.message,
								type: 'error'
							});
						} else {
							this.$refs['goodsForm'].resetFields();
							this.LookList = res.data.list;
							this.loading = false;
							this.goodsdialog= false;
						}
					});
				}
			},
			//获取用户列表 判断用户是否在那个列表中
			getUsers: function(type) {
				var Token = sessionStorage.getItem('Token');
				var timestamp=new Date().getTime();
				let para = {
					token: Token,
					curpage:this.page,
					pagesize:this.size,
					timestamp: timestamp
				};
				this.loading = true;
				getGoodsUser(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.total = res.data.total;
						this.List = res.data.list;
						this.loading = false;
					}
				});
			},
		},
		beforeDestroy() {
		  clearInterval(this.timer);        
		  this.timer = null;
		}
	};
</script>

<style scoped>
.el-button.is-disabled{
	color: #bfcbd9;
	    cursor: not-allowed;
	    background-image: none;
	    background-color: #eef1f6;
	    border-color: #d1dbe5;
}
.el-pagination {
    white-space: nowrap;
    padding: 2px 5px;
    color: #48576a;
}
.demo-table-expand {
	/* display: flex;
	flex-direction: column; */
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 33.33%;
  }
  .detail{
	  float: left;width: 50%;margin-bottom:10px;display: flex;flex-direction: column;align-items: baseline;
  }
  .text{
  	font-family: "arial, helvetica, sans-serif";
  	font-size: 14px;
  	color: #333;
  	margin-top: 8px;
  	margin-left: 10px;
  	font-weight: 600;
  }
</style>
